package com.zhuang.designpattern.singleton;

/**
 * description: 使⽤用类的内部类(线程安全)
 * date: 2022/9/14 18:29
 * author: Zhuang
 * version: 1.0
 */
public class Singleton_04 {
    public static void main(String[] args) {
        Singleton04 instance1 = Singleton04.getInstance();
        Singleton04 instance2 = Singleton04.getInstance();

        System.out.println("instance1 = " + instance1);
        System.out.println("instance2 = " + instance2);
    }
}

class Singleton04 {
    private static class SingletonHolder {
        private static final Singleton04 instance = new Singleton04();
    }

    private Singleton04() {
    }

    public static Singleton04 getInstance() {
        return SingletonHolder.instance;
    }
}
